package com.gyyweishang.mapper;

import com.gyyweishang.pojo.Emp;
import com.gyyweishang.pojo.EmpQueryParam;
import com.gyyweishang.pojo.LoginInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 员工信息
 */
@Mapper
public interface EmpMapper {

    //----------------------原始分页查询实现---------------------------------
    /**
     * 查询总记录数
     */
//    @Select("Select count(*) from emp left join dept on emp.dept_id = dept.id")
//    Long searchEmpInfoTotal();

    /**
     * 分页查询数据
     */
//    @Select("Select emp.*, dept.name as deptName from emp left join dept on emp.dept_id = dept.id " +
//            "order by emp.update_time desc offset #{start} rows fetch next #{pageSize} rows only")
//    List<Emp> searchEmpInfo(Integer start, Integer pageSize);


//@Select("select emp.*, dept.name as deptName from emp left join dept on emp.dept_id = dept.id order by emp.update_time")
//    List<Emp> list();


    /**
     * 条件查询员工信息
     */
    List<Emp> list(EmpQueryParam empQueryParam);

    /**
     * 新增员工基本信息
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")//为对象emp获取生成的主键id值，主键返回
    @Insert("insert into emp (username, name , gender, phone, job, salary, image,  entry_date,dept_id,create_time, update_time ) " +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime}) " )
    void insert(Emp emp);

    /**
     * 批量删除员工信息
     * @param ids
     */
    void deleteByIds(List<Integer> ids);

    /**
     * 根据id查询员工信息
     */
    @Select("select e.id,username,e.password,e.name,gender,phone,job,salary,image,entry_date as entryDate,dept_id as deptId,\n" +
            " e.create_time as createTime,e.update_time as updateTime,d.name deptName  from emp e \n" +
            "left join dept d on e.dept_id=d.id  where e.id = #{id}")
    Emp getInfo(Integer id);

    /**
     * 更新员工信息
     * @param emp
     */
    void updateInfo(Emp emp);

    /**
     * 根据用户名和密码查询用户
     * @param emp
     * @return
     */
    @Select("select id,username,name from emp where username = #{username} and password = #{password}")
    Emp selectByUserNameAndPassword(Emp emp);
}
